<template>
	<div>
		<!-- :visible.sync="$store.state.mealflag" -->
			<el-button type="text" @click="dialogVisible = true">添加套餐</el-button>
		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="套餐信息" :visible.sync="dialogVisible" width="30%"
		 center>
			<span>
				<!-- ////////////////////// -->
				<el-form ref="form" label-width="80px">
					<el-form-item label="套餐名称">
						<el-input v-model="mealInfo.mealname" maxlength=15></el-input>
					</el-form-item>
					<el-form-item label="套餐时间">
						<el-input v-model="mealInfo.mealtime" maxlength=5 @keyup.native="trim1()" style="width:40%"></el-input> 天
					</el-form-item>
					<el-form-item label="套餐价格">
						<el-input v-model="mealInfo.mealmoney" maxlength=15 @keyup.native="trim()" style="width:40%"></el-input> 元
					</el-form-item>
					<el-form-item label="是否启用">
						<el-switch v-model="mealInfo.mealstate"></el-switch>
					</el-form-item>
					<!-- 		  <el-form-item label="活动性质">
		    <el-checkbox-group v-model="mealInfo.mealtype">
		      <el-checkbox label="长期套餐" name=1></el-checkbox>
		      <el-checkbox label="短期套餐" name=2></el-checkbox>
		    </el-checkbox-group>
		  </el-form-item> -->
					<el-form-item label="活动性质">
						<el-radio v-model="mealInfo.mealtype" :label="lab1">长期套餐</el-radio>
						<el-radio v-model="mealInfo.mealtype" :label="lab2">短期套餐</el-radio>
					</el-form-item>
					<el-form-item label="套餐内容">
						<el-input type="textarea" v-model="mealInfo.mealmsg" maxlength=55></el-input>
					</el-form-item>
				</el-form>
				<!-- ////////////////////// -->
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="mealflag(false)">添加</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		request
	} from "network/request.js"
	export default {
		data() {
			return {
				dialogVisible:false,
				lab1: 1,
				lab2: 2,
				flag: false,
				flag2: true,
				mealstate2:"1",
				mealInfo: {
					mealid: 1,
					mealname: '',
					mealmsg: '',
					mealtype: 1,
					mealstate: true,
					mealmoney: 0,
					mealtime: 30,
					mealremark: '8',
				}
			};
		},
		methods: {
			mealflag(flag) {
				if(this.mealInfo.mealstate==true){
					this.mealstate2="1";
				}else{
				this.mealstate2="0"
				}
				request({
					url: '/Meal/Meals',
					method: 'post',
					data: {
						// id:this.$store.state.mealid
							"mealid": this.mealInfo.mealid,
							"mealmoney":this.mealInfo.mealmoney,
							"mealmsg": this.mealInfo.mealmsg,
							"mealname": this.mealInfo.mealname,
							"mealremark": "string",
							"mealstate": this.mealstate2,
							"mealtime": this.mealInfo.mealtime,
							"mealtype":this.mealInfo.mealtype
					}
				}).then(res => {
					this.$router.push("blank_emt")
					
				})
			},
			trim() {
				this.mealInfo.mealmoney = this.mealInfo.mealmoney.replace(/[^0-9\.]/g, '')
				// console.log(this.form.name)
			},
			trim1() {
				this.mealInfo.mealtime = this.mealInfo.mealtime.replace(/[^0-9]/g, '')
				// console.log(this.form.name)
			}
		}
	};
</script>

<style>
</style>
